/**
 * Created by Myron on 2015/8/15.
 */
var async = require('async');
var config = require('../config.js'); //必要
var wxjsapi = require('wx_jsapi_sign'); //微信分享必要
var fs = require('fs');
var OAuth = require('wechat-oauth'); //获取微信登陆信息 2015-02-14
var client = new OAuth(config.wx.app_id, config.wx.app_secret);
var request = require('request');
var MyronWX=require('../lib/MyronWx.js');

module.exports = {
    //分享页面测试代码
    del:function(req,res){
        res.render('myron/del',{});
    },
    share: function (req, res) {
        var url = req.url;
        console.log(url);
        var wxconfig={
            appId: config.wx.app_id,
            appSecret: config.wx.app_secret,
            cache_json_file:config.wx.cache_json_file
        };
        wxjsapi.getSignature(wxconfig)('http://'+config.domain+url, function(error, result) {
            if (error) {
                res.json({
                    'error': error
                });
            } else {
                console.log(result.signature);
                res.render('myron/share',{appId:result.appId,timestamp:result.timestamp,nonceStr:result.nonceStr,signature:result.signature});
                //res.json(result);
            }
        });
    },
    //微信推送消息模板给客户
    messages:function (req, res) {
        var url = req.url;
        var wxconfig={
            appId: config.wx.app_id,
            appSecret: config.wx.app_secret,
            cache_json_file:config.wx.cache_json_file
        };
        var openid=req.AV.user.get('openid');
        MyronWX.getUserInfo(wxconfig,openid).then(function(UserInfo){
            console.log("+++++++++++++++获取UserInfo+++++++++++++++"+UserInfo);
            console.log(UserInfo.subscribe); //关注过UserInfo.subscribe是 1  没有关注过是0
        });

         res.json({headimgurl:req.AV.user.get('headimgurl'),User:req.AV.user});

    }
}


